/*
	Filename	:	bjRuleSets.cpp
	Author(s)	:	Ray E. Bornert II
	Date		:	2002-MAR-26
	Copyright	:	(c) 2002 RealTimeGaming

	History		:
*/

//////////////
// INCLUDES //
//////////////
#include "bjrules.h"
#include <string.h>

void BJRules::InitRules_Common()
{
	//number of decks for the shoe
	m_nDecks			= 8;
	m_nBJBets			= 1;


	//rtg client can handle 3 hands
	m_maximumHands		= 3;

	//this is universal for the game of 21
	m_playerBustTotal	=22;
	m_dealerBustTotal	=22;

	/// [2013-07-16] Charles. Added for supporting 'Zappit Rackcard'.
	m_dealerPushTotal	= 0;

	//normal 1 to 1 payout for a win, tied hands are pushed
	m_payoutWin			= 1.0;		//units to add to a normal win
	m_payoutLoss		=-1.0;		//units to add to a normal loss
	m_payoutTie			= 0.0;		//units to add to a normal tie

	//this isn't likely to ever change
	m_insureBet			= 0.5;		//percentage of original bet
	m_insurePayout		= 2.0;		//units to add to a winning insure bet

	//and neither is this
	m_surrenderPayout	=-0.5;		//player loses half of bet

	//the most common deal
	SetDealScript( "PdPD" );
}
 
void BJRules::InitRules_StandardBlackjack()
{
	//setup the most common parameters
	InitRules_Common();

	//                                                       1stCard     hand
	//ACTION       Who  Action    nHands nCards total  soft  pattern   pattern
	//====================================================================================
	AddRuleAction( 'P', Bet      , 0,0,   0,0,   0,0 , 0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Hit      , 1,1,   0,20,  0,20, 0,1,  ""  ,     ""       );
	AddRuleAction( 'P', Hit      , 2,2,   1,1,   0,20, 0,1,  "A*",     ""       );
	AddRuleAction( 'P', Hit      , 2,3,   0,20,  0,20, 0,1,  "a*",     ""       );
	AddRuleAction( 'P', Stand    , 1,3,   2,21,  0,99, 0,1,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 1,3,   2,2,   0,20, 0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 1,1,   2,2,   0,21, 1,1,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 2,3,   2,2,   0,21, 1,1,  "a*",     ""       );
	AddRuleAction( 'P', Split    , 1,1,   2,2,   0,99, 0,1,  ""  ,     "V*V*"   );
	AddRuleAction( 'P', Split    , 2,2,   2,2,   0,99, 0,1,  "a*",     "V*V*"   );
	AddRuleAction( 'P', Surrender, 1,1,   2,2,  16,16, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Hit      , 0,3,   0,20,  0,16, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Hit      , 0,3,   0,20,  0,17, 1,1,  ""  ,     ""       );
	AddRuleAction( 'D', Stand    , 0,3,   0,20, 17,99, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Stand    , 0,3,   0,20, 18,99, 1,1,  ""  ,     ""       );
	AddRuleAction( 'P', EOG      , 1,1,   2,2,   0,99, 0,1,  ""  ,     ""       );
	AddRuleAction( 'D', EOG      , 1,1,   2,2,  21,21, 1,1,  ""  ,     "X*A*"   );

	//                                                                  total payout
	//BONUS      who,type, name      ,pattern,nHands,nCards,total,nBets,bonus,bonus
	//=================================================================================
	AddRuleBonus('P', 'W',"BlackJack","X*A*" ,  1,1 ,  2,2 ,21,21, 1,1 , 100 ,  0.5   );
	AddRuleBonus('D', 'W',"BlackJack","X*A*" ,  1,3 ,  2,2 ,21,21, 0,0 , 100 ,  0.0   );

	// PRECLUSIONS [b][a] - is a allowed after b?

	//              before    after
	//====================================
	SetPreclusions( "BHPDR"	, Stand		);
	SetPreclusions( "BHP"	, Hit		);
	SetPreclusions( "BHP"	, Double	);
	SetPreclusions( "BHP"	, Split		);
	SetPreclusions( "B"		, Surrender	);
}

void BJRules::InitRules_Pontoon()
{
	//setup the most common parameters
	InitRules_Common();

	//ties go to the dealer
	m_payoutTie			=-1.0;		//dealer wins ties

	m_insureBet			= 0.0;		//not offered
	m_insurePayout		= 0.0;		//not offered

	//unique deal
	SetDealScript( "Pdd" );

	//                                                       1stCard     hand
	//ACTION       Who  Action    nHands nCards total  soft  pattern   pattern
	//====================================================================================
	AddRuleAction( 'P', Bet      , 0,0,   0,0,   0,0 , 0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Hit      , 1,3,   0,4,   0,20, 0,1,  ""  ,     ""       );
	AddRuleAction( 'P', Stand    , 1,3,   2,4,  15,99, 0,1,  ""  ,     ""       );
	AddRuleAction( 'P', Stand    , 1,3,   5,22,  0,99, 0,1,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 1,1,   1,4,   0,20, 0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 1,1,   1,4,   0,21, 1,1,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 2,3,   2,4,   0,20, 0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 2,3,   2,4,   0,21, 1,1,  ""  ,     ""       );
	AddRuleAction( 'P', Split    , 1,2,   2,2,   0,99, 0,1,  ""  ,     "=*=*"   );
	AddRuleAction( 'P', Surrender, 1,1,   2,2,  16,16, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Hit      , 0,3,   0,4,   0,16, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Hit      , 0,3,   0,4,   0,17, 1,1,  ""  ,     ""       );
	AddRuleAction( 'D', Stand    , 0,3,   0,4,  17,99, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Stand    , 0,3,   0,4,  18,99, 1,1,  ""  ,     ""       );
	AddRuleAction( 'D', Stand    , 0,3,   5,22,  0,99, 0,1,  ""  ,     ""       );
	AddRuleAction( 'P', EOG      , 1,1,   2,2,   0,99, 0,1,  ""  ,     ""       );
	AddRuleAction( 'D', EOG      , 1,1,   2,2,  21,21, 1,1,  ""  ,     "X*A*"   );


	//                                                                  total payout
	//BONUS      who,type, name      ,pattern,nHands,nCards,total,nBets,bonus,bonus
	//=================================================================================
	AddRuleBonus('D', 'W',"Pontoon"  ,"X*A*" ,  1,3 ,  2,2 ,21,21, 0,0 , 400 ,  0.0   );
	AddRuleBonus('P', 'W',"Pontoon"  ,"X*A*" ,  1,3 ,  2,2 ,21,21, 1,2 , 300 ,  1.0   );
	AddRuleBonus('D', 'W',"5-Cards"  ,""     ,  1,3 ,  5,5 , 5,21, 0,0 , 200 ,  0.0   );
	AddRuleBonus('P', 'W',"5-Cards"  ,""     ,  1,1 ,  5,5 , 5,21, 1,16, 100 ,  1.0   );

	// PRECLUSIONS [b][a] - is a allowed after b?

	//              before    after
	//====================================
	SetPreclusions( "BHPDR"	, Stand		);
	SetPreclusions( "BHPD"	, Hit		);
	SetPreclusions( "BHPD"	, Double	);
	SetPreclusions( "BHPD"	, Split		);
	SetPreclusions( "BH"	, Surrender	);
}

void BJRules::InitRules_DoubleExposure21()
{
	//setup the most common parameters
	InitRules_Common();

	//ties go to the dealer
	m_payoutTie			=-1.0;		//dealer wins ties

	//insurance not offered
	m_insureBet			= 0.0;		//not offered
	m_insurePayout		= 0.0;		//not offered

	//unique deal
	SetDealScript( "PDPD" );

	//                                                       1stCard     hand
	//ACTION       Who  Action    nHands nCards total  soft  pattern   pattern
	//====================================================================================
	AddRuleAction( 'P', Bet      , 0,0,   0,0,   0,0,  0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Hit      , 1,1,   0,20,  0,20, 0,1,  ""  ,     ""       );
	AddRuleAction( 'P', Hit      , 2,2,   1,1,   0,20, 0,1,  "A*",     ""       );
	AddRuleAction( 'P', Hit      , 2,3,   0,20,  0,20, 0,1,  "a*",     ""       );
	AddRuleAction( 'P', Stand    , 1,3,   2,21,  0,99, 0,1,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 1,3,   2,2,   9,11, 0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Split    , 1,1,   2,2,   0,99, 0,1,  ""  ,     "V*V*"   );
	AddRuleAction( 'P', Split    , 2,2,   2,2,   0,99, 0,1,  "a*",     "V*V*"   );
	AddRuleAction( 'P', Surrender, 1,1,   2,2,  16,16, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Hit      , 0,3,   0,20,  0,16, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Hit      , 0,3,   0,20,  0,17, 1,1,  ""  ,     ""       );
	AddRuleAction( 'D', Stand    , 0,3,   0,20, 17,99, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Stand    , 0,3,   0,20, 18,99, 1,1,  ""  ,     ""       );
	AddRuleAction( 'P', EOG      , 1,1,   2,2,   0,99, 0,1,  ""  ,     ""       );
	AddRuleAction( 'D', EOG      , 1,1,   2,2,  21,21, 1,1,  ""  ,     "X*A*"   );


	//                                                                  total payout
	//BONUS      who,type, name      ,pattern,nHands,nCards,total,nBets,bonus,bonus
	//=================================================================================
	AddRuleBonus('D', 'W',"BlackJack", "X*A*",  1,3 ,  2,2 ,21,21, 0,0 , 100,  0.0   );
	AddRuleBonus('P', 'W',"BlackJack", "X*A*",  1,1 ,  2,2 ,21,21, 1,1 , 200,  0.0   );

	// PRECLUSIONS [b][a] - is a allowed after b?

	//              before    after
	//====================================
	SetPreclusions( "BHPDR"	, Stand		);
	SetPreclusions( "BHP"	, Hit		);
	SetPreclusions( "B"		, Double	);
	SetPreclusions( "B"		, Split		);
	SetPreclusions( "B"		, Surrender	);

}
 
// bwardlow 29-Aug-2006 #14722 disable Caribbean 21
/*
void BJRules::InitRules_Caribbean21()
{
	//setup the most common parameters
	InitRules_Common();

	m_isHardAces		= 1;	//aces always valued at 1

	//ties go to the dealer
	m_payoutTie			=-1.0;	//dealer wins ties

	//Insurance pays 9 to 1
	m_insurePayout		= 9.0;

	//unique deal
	SetDealScript( "D" );

	//                                                       1stCard     hand
	//ACTION       Who  Action    nHands nCards total  soft  pattern   pattern
	//====================================================================================
	AddRuleAction( 'P', Bet      , 0,0,   0,0,   0,0,  0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Hit      , 1,3,   0,20,  0,20, 0,1,  ""  ,     ""       );
	AddRuleAction( 'P', Stand    , 1,3,   2,22,  0,99, 0,1,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 1,3,   0,20,  0,20, 0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 1,3,   0,20,  0,21, 1,1,  ""  ,     ""       );
	AddRuleAction( 'P', Split    , 1,2,   2,2,   0,21, 0,1,  ""  ,     ""       );
	AddRuleAction( 'P', Surrender, 1,3,   2,20, 12,20, 0,1,  ""  ,     ""       );
	AddRuleAction( 'D', Hit      , 0,3,   0,20,  0,16, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Stand    , 0,3,   0,99, 17,99, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Hit      , 0,3,   0,20,  0,17, 1,1,  ""  ,     ""       );
	AddRuleAction( 'D', Stand    , 0,3,   0,99, 18,99, 1,1,  ""  ,     ""       );

	//                                                                  total payout
	//BONUS      who,type, name      ,pattern,nHands,nCards,total,nBets,bonus,bonus
	//=================================================================================
	AddRuleBonus('D', 'W',"Caribbean","X*X*A*",1,3  , 3,3  ,21,21, 0,0 , 100,  0.0  );
	AddRuleBonus('P', 'W',"Caribbean","X*X*A*",1,3  , 3,3  ,21,21, 1,4 , 100,  0.0  );

	// PRECLUSIONS [b][a] - is a allowed after b?

	//              before    after
	//====================================
	SetPreclusions( "BHPDR"	, Stand		);
	SetPreclusions( "BHPD"	, Hit		);
	SetPreclusions( "BHPD"	, Double	);
	SetPreclusions( "BHP"	, Split		);
	SetPreclusions( "BHPD"	, Surrender	);
}
*/

void BJRules::InitRules_Super21()
{
	//setup the most common parameters
	InitRules_Common();

	//                                                       1stCard     hand
	//ACTION       Who  Action    nHands nCards total  soft  pattern   pattern
	//====================================================================================
	AddRuleAction( 'P', Bet      , 0,0,   0,0,   0,0,  0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Stand    , 1,3,   2,21,  0,99, 0,1,  ""  ,     ""       );
	AddRuleAction( 'P', Hit      , 1,3,   0,20,  0,20, 0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Hit      , 1,3,   0,20,  0,21, 1,1,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 1,3,   2,20,  0,20, 0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 1,3,   2,20,  0,21, 1,1,  ""  ,     ""       );
	AddRuleAction( 'P', Split    , 1,2,   2,2,   0,99, 0,1,  ""  ,     "V*V*"   );
	AddRuleAction( 'P', Surrender, 1,3,   2,20,  0,20, 0,1,  ""  ,     ""       );
	AddRuleAction( 'D', Hit      , 0,3,   0,20,  0,16, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Hit      , 0,3,   0,20,  0,17, 1,1,  ""  ,     ""       );
	AddRuleAction( 'D', Stand    , 0,3,   0,20, 17,99, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Stand    , 0,3,   0,20, 18,99, 1,1,  ""  ,     ""       );
	AddRuleAction( 'P', EOG      , 1,1,   2,2,   0,99, 0,1,  ""  ,     ""       );
	AddRuleAction( 'D', EOG      , 1,1,   2,2,  21,21, 1,1,  ""  ,     "X*A*"   );

	//                                                                  total payout
	//BONUS      who,type, name      ,pattern,nHands,nCards,total,nBets,bonus,bonus
	//=================================================================================
	AddRuleBonus('P', 'W',"5-Card 21",""     , 1,3  , 5,21 ,21,21, 1,1 , 200 ,  1.0   );
	AddRuleBonus('P', 'W',"6-Cards"  ,""     , 1,3  , 6,6  , 6,20, 1,1 , 200 ,  0.0   );
	AddRuleBonus('P', 'W',"Diamond21","XDAD" , 1,1  , 2,2  ,21,21, 1,1 , 200 ,  1.0   );
	AddRuleBonus('P', 'W',"BlackJack","X*A*" , 1,1  , 2,2  ,21,21, 1,1 , 200 ,  0.0   );
	AddRuleBonus('D', 'W',"BlackJack","X*A*" , 1,3  , 2,2  ,21,21, 0,0 , 100 ,  0.0   );

	// PRECLUSIONS [b][a] - is a allowed after b?

	//              before    after
	//====================================
	SetPreclusions( "BHPDR"	, Stand		);
	SetPreclusions( "BHP"	, Hit		);
	SetPreclusions( "BHP"	, Double	);
	SetPreclusions( "BHP"	, Split		);
	SetPreclusions( "BHPD"	, Surrender	);
} 

void BJRules::InitRules_Spanish21()
{
	//setup the most common parameters
	InitRules_Common();

	//               --AKQJ098765432-
	m_deckFilter = 0x000000F000000000; //no 10's

	//                                                       1stCard     hand
	//ACTION       Who  Action    nHands nCards total  soft  pattern   pattern
	//====================================================================================
	AddRuleAction( 'P', Bet      , 0,0,   0,0,   0,0,  0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Stand    , 1,3,   2,21,  0,99, 0,1,  ""  ,     ""       );
	AddRuleAction( 'P', Hit      , 1,3,   0,20,  0,20, 0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Hit      , 1,3,   0,20,  0,21, 1,1,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 1,3,   2,20,  0,20, 0,0,  ""  ,     ""       );
	AddRuleAction( 'P', Double   , 1,3,   2,20,  0,21, 1,1,  ""  ,     ""       );
	AddRuleAction( 'P', Split    , 1,2,   2,2,   0,99, 0,1,  ""  ,     "V*V*"   );
	AddRuleAction( 'P', Surrender, 1,3,   2,20,  0,20, 0,1,  ""  ,     ""       );
	AddRuleAction( 'D', Hit      , 0,3,   0,20,  0,16, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Hit      , 0,3,   0,20,  0,17, 1,1,  ""  ,     ""       );
	AddRuleAction( 'D', Stand    , 0,3,   0,20, 17,99, 0,0,  ""  ,     ""       );
	AddRuleAction( 'D', Stand    , 0,3,   0,20, 18,99, 1,1,  ""  ,     ""       );
	AddRuleAction( 'P', EOG      , 1,1,   2,2,   0,99, 0,1,  ""  ,     ""       );
	AddRuleAction( 'D', EOG      , 1,1,   2,2,  21,21, 1,1,  ""  ,     "X*A*"   );


	//                                                                  total payout
	//BONUS      who,type, name      ,pattern,nHands,nCards,total,nBets,bonus,bonus  duc
	//====================================================================================
	AddRuleBonus('P','W',"Spanish21" ,"7=7=7=", 1,1 , 3,3  ,21,21, 1,1 , 400 ,200.0, "7*");
	AddRuleBonus('P','W',"BlackJack" ,"X*A*"  , 1,1 , 2,2  ,21,21, 1,1 , 300 ,  0.5   );
	AddRuleBonus('D','W',"BlackJack" ,"X*A*"  , 1,3 , 2,2  ,21,21, 0,0 , 200 ,  0.0   );
	AddRuleBonus('P','W',"678 Spades","6S7S8S", 1,1 , 3,3  ,21,21, 1,1 , 100 ,  2.0   );
	AddRuleBonus('P','W',"678 Suited","6=7=8=", 1,1 , 3,3  ,21,21, 1,1 , 100 ,  1.0   );
	AddRuleBonus('P','W',"6-7-8"     ,"6*7*8*", 1,1 , 3,3  ,21,21, 1,1 , 100 ,  0.5   );
	AddRuleBonus('P','W',"777 Spades","7S7S7S", 1,1 , 3,3  ,21,21, 1,1 , 100 ,  2.0   );
	AddRuleBonus('P','W',"777 Suited","7=7=7=", 1,1 , 3,3  ,21,21, 1,1 , 100 ,  1.0   );
	AddRuleBonus('P','W',"7-7-7"     ,"7*7*7*", 1,1 , 3,3  ,21,21, 1,1 , 100 ,  0.5   );
	AddRuleBonus('P','W',"5-Card 21" ,""      , 1,1 , 5,5  ,21,21, 1,1 , 100 ,  0.5   );
	AddRuleBonus('P','W',"6-Card 21" ,""      , 1,1 , 6,6  ,21,21, 1,1 , 100 ,  1.0   );
	AddRuleBonus('P','W',"7-Card 21" ,""      , 1,1 , 7,21 ,21,21, 1,1 , 100 ,  2.0   );
	AddRuleBonus('P','W',"TwentyOne" ,""      , 1,3,  3,21 ,21,21, 1,1 , 100 ,  0.0   );

	// PRECLUSIONS [b][a] - is a allowed after b?

	//              before    after
	//====================================
	SetPreclusions( "BHPDR"	, Stand		);
	SetPreclusions( "BHP"	, Hit		);
	SetPreclusions( "BHP"	, Double	);
	SetPreclusions( "BHP"	, Split		);
	SetPreclusions( "BHPD"	, Surrender	);
}

//psharpless 12/20/06 Case: 16101
void BJRules::InitRules_PerfectPairs()
{
	//Perfect Pairs uses the same ruleset as standard blackjack
	InitRules_StandardBlackjack();
}

/// [2013-07-09] Charles. Added for supporting 'Zappit Rackcard'.
void BJRules::InitRules_Zappit()
{
	InitRules_StandardBlackjack();

	//                                                       1stCard     hand
	//ACTION       Who  Action		nHands	nCards total	soft  pattern   pattern
	//====================================================================================
	AddRuleAction( 'P',		Zap,			1,1,			2,2,		15,17,		0,0,	""  ,			"");

	// PRECLUSIONS [b][a] - is a allowed after b?
	//              before    after
	//====================================
	SetPreclusions( "Z"	, Stand		);
	SetPreclusions( "Z"	, Hit		);
	SetPreclusions( "Z"	, Double	);
	SetPreclusions( "Z"	, Split		);
	SetPreclusions( "Z"	, Surrender	);
	SetPreclusions( "B", Zap	);

	// Reset bust value
	m_dealerBustTotal	= 23;
	m_dealerPushTotal	= 22;
}
